<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<!-- 是否显示提交按钮 -->
<sys:funcAuth resCd="SplSubmit">
	<span id="isShowCmtBtn" />
</sys:funcAuth>
<!-- 是否显示审核按钮 -->
<sys:funcAuth resCd="SplCheck">
	<span id="isShowAudBtn" />
</sys:funcAuth>
<script type="text/javascript">
	var grid = null;
	var _mfrId;
	$(function () {
		_mfrId = '${mfrId}';
		var _url = '<%=path%>/product/splCrLim/initList.do?isEncrypt=1&mfrId=' + _mfrId ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '供应商名称', align:'left', width: 180,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.splNm+'</a>';
	                	return h;
	            	}	
	            },
	            { display: '营业执照号', name: 'bizLicNo', align:'left', width: 140 },
	            { display: '税务登记号', name: 'taxRegNo', align:'left', width: 140 },
	            { display: '组织机构代码号', name: 'orgCode', align:'left', width: 140 },
	            { display: '所属机构', name: 'buOrgCdNms', align:'left', width: 140 ,
	            	render: function (rowdata, rowindex, value){
	                    var h='<span class="gridTip" title="'+ value +'">'+ value +'</span>'
	                    return h;
	                }
	            },
	            { display: '实际控制人', name: 'rlNm', width: 90 },
	            { display: '联系方式', name: 'tel', width: 90},
	            //{ display: '审核状态', name: 'audStsCdNm', width: 80 },
	            { display: '操作', width: 100 , align:'left',
	            	render: function (rowdata, rowindex, value){
	            		return '<a class="sq-button-hasicon" href="javascript:add('+"'"+rowdata.id+"'"+','+"'"+rowdata.splNm+"'"+')">增加授信</a>';
	            	}
	            }
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:false,
	        rownumbers:true,
	        frozen: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function ()
            {
                var grid = this;
                grid.collapsedRows = [];
            },
            
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "brCd": " ",
	            "audStsCd": " ",
	            "buOrgCd": " "
	        });
	    });
	});
	
	 //新增数据
	var callback = function () {
		grid.reload();
    };
    function getPrjSplCrList(limId){
    	$.ligerDialog.SQopen({
            width: 900,
            height:580,
            title : '授信使用情况',
            url:'<%=path%>/product/splCrLim/toPrjSplCrLimListPage.do?mfrId='+_mfrId+'&limId='+limId,
            buttons: [ {
	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
        	]

        });
    }
	function add(id,splNm){
		
        $.ligerDialog.SQopen({
            width: 800,
            height:380,
            title : splNm+'新增授信',
            url:'<%=path%>/product/splCrLim/toAddSplCrLimPage.do?mfrId='+_mfrId+'&splId='+id,
            buttons: [{
                	text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
        	]

        });
	}
	//审核
	function changeAudStsCd(_id){
		$.ligerDialog.SQopen({
            width: 500,
            height:200,
            title : '审核信息',
            url:'<%=path%>/product/splInfo/toModifyAudStsCdPage.do?id='+_id,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//提交  修改审核状态(审核中)
	function modifyAudStsCd(_id,_audStsCd){
	    if(!_id || !_audStsCd)return;
	    var url = '<%=path%>/product/splInfo/modifyAudStsCd.do';
	    var wait_dialog;
	    $.ajax({
			type: 'post',
			dataType:'json',
			data:{
				id:_id,
				audStsCd:_audStsCd
			},
			url: url,
			beforeSend: function(){
		          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 grid.reload();
				 }else{
					 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	
	function toSplBankList(_id){
		if(!_id)return;
		Add_navTab('PrdSpl_4'+_id,'供应商账号',"<%=path%>/product/splBank/toListPage.do?splId="+_id);
	}
	 //修改数据
	function change(_id){
		if(!_id)return;
		if(_mfrId==""){
			Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id, callback);
		}else{
			Add_navTab('PrdSpl_2'+_id,'修改供应商','<%=path%>/product/splInfo/toAddPage.do?id='+_id+'&mfrId='+_mfrId, callback);
		}
	};
	//详情
	function showDetail(_id){
		if(!_id)return;
		if(_mfrId==""){
			parent.mainApp.f_addTab('PrdSpl_3'+_id,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+_id);
		}else{
			parent.parent.mainApp.f_addTab('PrdSpl_3'+_id,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+_id);
		}
	}
	//删除数据
	function deleteRecord(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/product/splInfo/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//逾期明细列表
    function showDetail_grid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            //url: '<%=path%>/invoice/prjbillbscinfo/initList.do?applyId='+row.id,
            url: '<%=path%>/product/splCrLim/crInitList.do?splId='+row.id,
            method: 'get',
            columns: [
                {display: '协议编号',name: 'licNo',width: 120,align:'center'},
                {display: '授信级别',name: 'lvl',width: 120,align:'center'},
                {display: '事业部',name: 'orgDispNm',width: 120,align:'center'},
                {display: '授信额', name: 'crAmtD', width: 90, align: 'center',
                	render: function (rowdata, rowindex, value){
                		return '<a class="sq-button-hasicon" href="javascript:getPrjSplCrList('+"'"+rowdata.id+"'"+')">'+value+'</a>';
                	}	
                },
                {display: '剩余授信额', name: 'restCrAmt', width: 90, align: 'center'},
                {display: '已用授信额', name: 'sumLimOpAmt', width: 90, align: 'center'},
                {display: '已还授信额', name: 'sumLimRbAmt', width: 90, align: 'center'},
                {display: '授信类型', name: 'crTypCd', width: 130, align: 'center',
                	render: function (rowdata, rowindex, value){
                		if(value == 1) return '循环';
                		if(value == 2) return '一次性';
                		
                	}
                },
                {display: '是否历史授信', name: 'isHis', width: 60, align: 'center',
                	render: function (rowdata, rowindex, value){
                		if(value == 0) return '否';
                		if(value == 1) return '是';
                	}
                },
                {display: '开始时间', name: 'startDt', width: 90, align: 'center',render:renderDate},
                {display: '结束时间', name: 'endDt', width: 90, align: 'center',render:renderDate}
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers:true,  //显示序号
            allowUnSelectRow:true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    } 
</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">供应商名称</div>
                <div class="field">
                    <input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
			<div class="fieldBox">
                <div class="label">审核状态</div>
                <div class="field">
                    <select name="audStsCd" id="audStsCd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${searchAudStsCdList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div>           
			<div class="fieldBox">
                <div class="label">所属事业部</div>
                <div class="field">
                    <select name="buOrgCd" id="buOrgCd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${searchBuOrgList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div>           
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
                <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>